package com.fary.service;

import com.fary.constant.SchedulerConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;

/**
 * 执行定时任务
 */
@Slf4j
@Service
public class ExecuteTaskService implements SmartInitializingSingleton {

    private final Map<String, Consumer<String>> taskMap = new HashMap<>();

    @Override
    public void afterSingletonsInstantiated() {
        taskMap.put(SchedulerConstant.CapacityTask, new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println("定时任务1");
            }
        });

    }

    public void doExecuteTask(String cornId) {
        taskMap.get(cornId).accept(cornId);
    }

}
